<?php

require_once dirname(__FILE__).'/../lib/employeeGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/employeeGeneratorHelper.class.php';

/**
 * employee actions.
 *
 * @package    Amawal Invest
 * @subpackage employee
 * @author     Ameen Shoman<amin.shoman@gmail.com>
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class employeeActions extends autoEmployeeActions
{
    public function executeActiviate(sfWebRequest $req){
        /*@var $emp Employee*/
        $emp = $this->getRoute()->getObject();
        if($emp->getInActive()){
            $emp->setInActive(0);
        }else{
            $emp->setInActive(1);
        }
        $emp->save();
        $this->getUser()->setFlash( 'notice' , __('Operation done successfully !') );
        $this->redirect('employee/index');
    }
    public function executeAjax_auto_complete(sfWebRequest $req){
    	$q = $req->getParameter('q');
    	$c= new Criteria();
    	$c->addJoin( EmployeeI18nPeer::ID   , EmployeePeer::ID  );
    	$c->add( EmployeeI18nPeer::FIRST_NAME   , "%$q%" , Criteria::LIKE );
    	$c->addOr( EmployeeI18nPeer::FOURTH_NAME  , "%$q%" , Criteria::LIKE );
    	
    	$arr = array();
    	foreach (EmployeePeer::doSelect($c) as $emp){
    		$arr[$emp->getId()] = $emp->__toString();
    	}
    	return $this->renderText(json_encode($arr));
    	$this->setTemplate('index');
    }
    
}
